# 必选参数 parameter
def printdetail1(name, age, telephone):
    print("姓名:", name)
    print("年龄:", age)
    print("电话:", telephone)


# 调用
printdetail1("Jack", 12, 12356435678)


# 默认参数parameter=value
def printdetail2(name, age, telephone, gender='fale'):
    print("姓名:", name)
    print("性别:", gender)
    print("年龄:", age)
    print("电话:", telephone)


# 调用
printdetail2("Jack", 12, 12356435678, gender='female')


# 可变参数*
# 1.不定长传参
def fun1(*number):
    for i in number:
        print(i)


# 调用
fun1(1, 2, 3, 4, 5, 6, 7, 8)


# 2.元组和列表的压包
def fun2(*number):
    s = 0
    for i in number:
        s += i
    print(s)


# 调用
fun2(*[1, 2, 3, 4, 5])
fun2(*(1, 2, 3, 4, 5))


# 关键参数**
# 使用方法一
def fun(id, name, **kargs):
    print("id:", id)
    print("name:", name)
    print("others:", kargs)


# 调用
fun(2, "xiaohua", sex="man", age='12')

# 使用方法二
extra = {'sex': 'man', 'age': 12}


def fun(id, name, **kargs):
    print("id:", id)
    print("name:", name)
    print("others:", kargs)


# 调用
fun(2, "xiaohua", sex=extra['sex'], age=extra['age'])

# 使用方法三
extra = {'sex': 'man', 'age': 12}


def fun(id, name, **kargs):
    print("id:", id)
    print("name:", name)
    print("others:", kargs)


# 调用
fun(2, "xiaohua", **extra)


# 关键字参数*
def fun(name, age, *, city, job, completion):
    print("name:", name)
    print("age:", age)
    print("city:", city)
    print("job:", job)
    print("completion:", completion)


# 调用
# 命名关键字参数需要一个特殊分隔符*，后面的参数被视为命名关键字参数 那么再调用的时候必须加上 形参名=传参值
# 如果函数定义中已经有了一个可变参数，后面跟着的命名关键字参数就不再需要一个特殊分隔符*了
fun('Jack', 12, city='shanghai', job='teacher', completion=True)


# 参数组合
def fun(parameter, *args, keyparameter, **kargs):
    print(parameter)
    print(args)
    print(keyparameter)
    print(kargs)


# 调用
# 参数定义的顺序必须是：必选参数、默认参数、可变参数、命名关键字参数和关键字参数
fun(1, *(1, 2, 3, 4), keyparameter=True, **{'id': 2})
